package com.bilibili.lzx.api;

import com.bilibili.lzx.dao.domain.JsonResponse;
import com.bilibili.lzx.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
public class FileApi {

    @Resource
    private FileService fileService;

    @PostMapping("/slices-files")
    public JsonResponse<String> uploadFileBySlices(MultipartFile slice,String fileMd5,Integer sliceNo,Integer totalSliceNo) throws Exception {
        String result = fileService.uploadFileBySlices(slice, fileMd5, sliceNo, totalSliceNo);
        return JsonResponse.success(result);
    }

    @PostMapping("/slices")
    public JsonResponse<String> fileSlices(MultipartFile file) throws Exception {
        System.out.println(file);
        String s = fileService.fileSlices(file);
        return JsonResponse.success(s);
        
    }

    @GetMapping("/md5-files")
    public JsonResponse<String> getFileMd5(MultipartFile file) throws Exception {
        String fileMd5 = fileService.getFileMd5(file);
        return JsonResponse.success(fileMd5);
    }

}
